package com.starfactory.customer.api;

import com.starfactory.customer.table.customUser.CustomUserMapper;
import com.starfactory.customer.shared.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.starfactory.customer.shared.dto.CustomUserVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.starfactory.customer.table.customUser.CustomUser;

@Service
@Slf4j
public class GetCustomDetailApi {
  @Autowired private CustomUserMapper customUserMapper;

  public Result<CustomUserVo> getCustomDetailApiApiFunction(String customUserId) {
    // 查询客户信息
    log.info("开始");
    QueryWrapper<CustomUser> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("customer_id", customUserId);
    CustomUser customUser = customUserMapper.selectOne(queryWrapper);
    // 客户信息不存在
    if (customUser == null) {
      return new Result<>(404, "客户不存在", null);
    }
    // 客户信息被删除
    if (customUser.getDeleteFlag() == 1) {
      return new Result<>(404, "客户不存在", null);
    }
    // 转换为CustomUserVo
    CustomUserVo customUserVo = new CustomUserVo();
    BeanUtils.copyProperties(customUser, customUserVo);
    return new Result<>(200, "查询成功", customUserVo);
  }
}
